package model

import (
	"fmt"

	"gitee.com/bluesky2006/ftp/logger"
	"github.com/szyhf/go-excel"
)

type Task struct {
	ID   string
	Name string `xlsx:"name"`
	Cron string `xlsx:"cron"`
}

func (task Task) String() string {
	return fmt.Sprintf("[TASK-%s]%s Cron:%s \n", task.ID, task.Name, task.Cron)
}

func GetAllTaskByExcel() (tasks []Task, error error) {
	filePath := "./conf/task.xlsx"
	logger.Info("file path is:", filePath)
	err := excel.UnmarshalXLSX(filePath, &tasks)
	if err != nil {
		logger.Error("error:", err)
		return nil, err
	}
	logger.Debug("task count:", len(tasks))
	return tasks, nil
}
